import java.util.ArrayList;
import java.util.Arrays;

public class Main {
    public static int solution(int n, int[] array) {
        // Edit your code here
        ArrayList<Integer> res = new ArrayList<>();

        for (int i=0; i < n; i++) {
            for (int j = i+1; j< array.length+1; j++) {
                int[] destination = new int[j-i];

                // 从original数组的索引1开始复制，共复制3个元素到destination数组的索引0处
                System.arraycopy(array, i, destination, 0, j-i);
                Arrays.sort(destination);
                res.add(destination[0]*(j-i));

            }
        }

        int maxVal = 0;
        for (int i =0; i< res.size(); i++) {
            if(res.get(i) > maxVal){
                maxVal = res.get(i);
            }
        }

        return maxVal;
    }

    public static void main(String[] args) {
        // Add your test cases here

        System.out.println(solution(5, new int[]{1, 2, 3, 4, 5}) == 9);
    }
}
